<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>循环定时器</title>
</head>
<body>
    <h2></h2>
    <script>
        //在h2标签中显示系统当前时间
        // setInterval(function(){
        //     var now=new Date()
        //     var h2=document.querySelector("h2");
        //     h2.innerHTML=now.toDateString()+' '+now.toTimeString()
        // },1000);
        setInterval(showTime,1000);
        function showTime() {
            var now=new Date();
            var h2=document.querySelector("h2");
            h2.innerHTML=now.toDateString()+' '+now.toTimeString();
        } 
        showTime();     
    </script>
</body>
</html>